package avicit.bdp.dds.api.controller;

import avicit.bdp.dds.api.service.MonitorService;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 监控器REST接口
 */
@Api(tags = "资源监控接口", position = 1)
@RestController
@RequestMapping("/api/bdp/dds/monitor")
public class MonitorController {

    private static final Logger logger = LoggerFactory.getLogger(MonitorController.class);

    @Autowired
    private MonitorService monitorService;

    /**
     * 监控master服务器信息
     */
    @ApiOperation(value = "监控master服务器信息")
    @GetMapping(value = "/master/list")
    public ResponseMsg<Map<String, Object>> listMaster() {

        Map<String, Object> result = monitorService.queryMaster();
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    /**
     * 监控worker服务器信息
     */
    @ApiOperation(value = "监控worker服务器信息", notes = "WORKER_LIST_NOTES")
    @GetMapping(value = "/worker/list")
    public ResponseMsg<Map<String, Object>> listWorker() {
        Map<String, Object> result = monitorService.queryWorker();
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    /**
     * 监控数据库状态
     */
    @ApiOperation(value = "监控数据库状态")
    @GetMapping(value = "/database")
    public  ResponseMsg<Map<String, Object>> queryDatabaseState() {
        Map<String, Object> result = monitorService.queryDatabaseState();
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    /**
     * 监控zookeeper状态
     */
    @ApiOperation(value = "监控zookeeper状态")
    @GetMapping(value = "/zookeeper/list")
    public  ResponseMsg<Map<String, Object>> queryZookeeperState() {
        Map<String, Object> result = monitorService.queryZookeeperState();
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

}
